package com.tiger.web.controller.project;


import com.tiger.common.annotation.Log;
import com.tiger.common.core.controller.BaseController;
import com.tiger.common.core.domain.AjaxResult;
import com.tiger.common.core.domain.model.LoginUser;
import com.tiger.common.core.page.TableDataInfo;
import com.tiger.common.enums.BusinessType;
import com.tiger.common.utils.ServletUtils;
import com.tiger.common.utils.spring.SpringUtils;
import com.tiger.framework.web.service.TokenService;
import com.tiger.project.domain.MaintenanceApply;
import com.tiger.project.domain.req.MaintenanceApplyBack;
import com.tiger.project.service.IMaintenanceApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 【请填写功能名称】Controller
 *
 * @author standard
 * @date 2022-09-16
 */
@Api(tags = "维修项目")
@RestController
@RequestMapping("/system/maintenanceApply")
public class MaintenanceApplyController extends BaseController {
    @Autowired
    private IMaintenanceApplyService maintenanceApplyService;

    /**
     * 查询【维修项目】列表
     */
    @ApiOperation(value = "查询【维修项目】列表")
    //@PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaintenanceApply maintenanceApply) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        maintenanceApply.setCompanyId(loginUser.getUser().getDeptId());
        startPage();
        List<MaintenanceApply> list = maintenanceApplyService.selectMaintenanceApplyList(maintenanceApply);
        return getDataTable(list);
    }


    /**
     * 获取【维修项目】详细信息
     */
    @ApiOperation(value = "获取【维修项目】列详细信息")
    //@PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(maintenanceApplyService.selectMaintenanceApplyById(id));
    }

    /**
     * 新增【维修项目】
     */
    @ApiOperation(value = "新增【维修项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:add')")
//    @Log(title = "新增【维修项目】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MaintenanceApply maintenanceApply) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        maintenanceApply.setCompanyId(loginUser.getUser().getDeptId());
        return toAjax(maintenanceApplyService.insertMaintenanceApply(maintenanceApply));
    }

    /**
     * 修改【维修项目】
     */
    @ApiOperation(value = "修改【维修项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:edit')")
//    @Log(title = "修改【维修项目】", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MaintenanceApply maintenanceApply) {
        return toAjax(maintenanceApplyService.updateMaintenanceApply(maintenanceApply));
    }

    /**
     * 删除【维修项目】
     */
    @ApiOperation(value = "删除【维修项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:remove')")
//    @Log(title = "删除【维修项目】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(maintenanceApplyService.deleteMaintenanceApplyByIds(ids));
    }

    @ApiOperation(value = "审核回调【维修项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:edit')")
//    @Log(title = "【维修项目】", businessType = BusinessType.UPDATE)
    @GetMapping("/callBack")
    public AjaxResult callBack(MaintenanceApplyBack maintenanceApplyBack) {
        return toAjax(maintenanceApplyService.callBack(maintenanceApplyBack));
    }
}
